package com.spzx.product.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.spzx.product.domain.ProductSpec;
import com.spzx.product.mapper.ProductSpecMapper;
import com.spzx.product.service.ICategoryService;
import com.spzx.product.service.IProductSpecService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class ProductSpecServiceImpl extends ServiceImpl<ProductSpecMapper, ProductSpec> implements IProductSpecService {
    @Autowired
    ProductSpecMapper productSpecMapper;

    @Autowired
    ICategoryService categoryService;

    /**
     * 商品规格的分页
     *
     * @param productSpec
     * @return
     */
    @Override
    public List<ProductSpec> selectAll(ProductSpec productSpec) {
        return productSpecMapper.selectproductSpecList(productSpec);
    }

    /**
     * 商品规格详细信息
     *
     * @param id
     * @return
     */
    @Override
    public ProductSpec selePoductSpecById(Long id) {
        ProductSpec productSpec = productSpecMapper.selectById(id);
        List<Long> categoryIdList = categoryService.getAllCategoryIdList(productSpec.getCategoryId());
        productSpec.setCategoryIdList(categoryIdList);
        return productSpec;
    }

    /**
     * 根据分类id获取商品规格列表
     *
     * @param categoryId
     * @return
     */
    @Override
    public List<ProductSpec> selectProductSpecListByCategoryId(Long categoryId) {
        return productSpecMapper.selectList(new LambdaQueryWrapper<ProductSpec>().eq(ProductSpec::getCategoryId, categoryId));
    }
}
